<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String info="";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title></title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/bootstrap-theme.min.css">
    <script src="js/jquery-1.12.3.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <meta content="UTF-8">	
    <!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body >
    <h1 style="text-align:center;color:blue">删除界面</h1><br>
    <form action="Delete.jsp" method="post" style="text-align:center">
        <label>请输入姓名：</label> <input type="text" name="name"><br>

        <input type="submit" value="确定" onclick="">           
    </form>
     <div>
          <table class="table table-bordered">
  
   <% 
     String name = request.getParameter("name");
     if(name==null)
        name="";
     if(!name.equals("")){
          Class.forName("com.mysql.jdbc.Driver").newInstance();  
          String url="jdbc:mysql://localhost:3306/AddressBook";  
          String user="root";   
          Connection conn = DriverManager.getConnection(url, user, "");  
          Statement st = conn.createStatement();  
          
          String sql ="select * from user where username ='"+name+"'";
          ResultSet Rs = st.executeQuery(sql);
          if(!Rs.next())               
            info ="无此人记录，所以无法删除!";
          else{
            String sql1 ="delete from user where username='"+name+"'";
            int  rs = st.executeUpdate(sql1);
            if(rs==1)
              info="删除成功!";
            else
              info="删除失败!";
          }
           %>              
            <tr>
            <td><%=info%>
            </td>       
            </tr>  
            <%  st.close();
                conn.close();}
             %>    
             </table>
             </div>                                                     
  </body>
</html>
